<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品销售统计</title>

    <link rel="stylesheet" href="http://cdn.viptool.cn/lib/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="http://cdn.viptool.cn/lib/animate.css/2.1.1/animate.min.css" rel="stylesheet">
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/switchery/0.8.2/switchery.min.css" rel="stylesheet"/>
    <link href="http://cdn.viptool.cn/lib/bootstrap-daterangepicker/2.1.25/daterangepicker.min.css" rel="stylesheet">
    <link href="../../resource/lib/imageview/css/imageviewer.css" rel="stylesheet"/>

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }

        .city-picker-selector select {

        }

        .daterangepicker {
            z-index: 999999999 !important;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="createTimePick">日期：</label>
                                <input type="text" class="form-control input-sm mb10 data-range-pick-custom"
                                       id="createTimePick" name="createTimePick" start-element="#beginDate"
                                       end-element="#endDate" placeholder="开始日期-结束日期" style="width: 277px;"/>
                                <input type="hidden" th:value="*{beginDate}" id="beginDate" name="beginDate"/>
                                <input type="hidden" th:value="*{endDate}" id="endDate" name="endDate"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button" onclick="saleGoodsList.search(1)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                </button>
                                <button type="button" onclick="saleGoodsList.searchAll()"
                                        class="btn btn-primary btn-sm m-b-none">显示全部
                                </button>

                                <button type="button" onclick="saleGoodsList.exportExcel()"
                                        class="btn btn-primary btn-sm m-b-none">导出
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <table class="table table-bordered table-hover table-center">
                                    <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>商品名</th>
                                        <th>类型</th>
                                        <th>总库存(件)</th>
                                        <th>销量(件)</th>
                                        <th>销售额(元)</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <!--/*@thymesVar id="row" type="com.shengtang.stagent.service.vo.sale.GoodsSaleInfoVO"*/-->
                                    <tr th:each="row,index:${saleInfo}">
                                        <td th:text="${index.count}">123123</td>
                                        <td th:text="${row.goodsName}">
                                        </td>
                                        <td th:switch="${row.goodsType}">
                                            <span class="text-danger" th:case="0" th:text="${row.goodsTypeDesc}"></span>
                                            <span class="text-info" th:case="1" th:text="${row.goodsTypeDesc}"></span>
                                            <span class="text-success" th:case="2" th:text="${row.goodsTypeDesc}"></span>
                                        </td>
                                        <td style="text-align: left;padding-left: 30px;">
                                            <span th:text="${row.totalStoreNum}"></span>
                                            <a type="button" class="btn-a" data-toggle="modal" data-target="#setGoodsStoreCount" th:onclick="|saleGoodsList.setStoreCount(${row.goodsId})|">设置库存</a>
                                            <br/>
                                            <!--销量：<span th:text="${row.totalSaleNum}"></span>-->
                                        </td>
                                        <td style="text-align: left;padding-left: 30px;" th:text="${row.totalSaleNum}">
                                        </td>
                                        <td style="text-align: left;padding-left: 30px;" th:text="${row.totalAmount}">
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal inmodal" id="setGoodsStoreCount" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated flipInY">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="modal-role-title">设置商品库存</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal m-t">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">库存数量：</label>
                        <div class="col-sm-8">
                            <input id="goodsId" name="goodsId" minlength="2" type="hidden" class="form-control" value="0">
                            <input id="storeCount" type="text" class="form-control OnlyFloat" name="storeCount">
                            <span>正整数即表示追加库存，负整数表示减库存</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">备注：</label>
                        <div class="col-sm-8">
                            <input id="remark" type="text" class="form-control" name="remark">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="saleGoodsList.btnSubmit()">保存</button>
            </div>
        </div>
    </div>
</div>
<!--基础框架js-->
<script src="http://cdn.viptool.cn/lib/jquery/2.2.4/jquery.min.js"></script>
<script src="http://cdn.viptool.cn/lib/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="http://cdn.viptool.cn/lib/moment.js/2.19.2/moment.min.js"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>
<script src="http://cdn.viptool.cn/lib/switchery/0.8.2/switchery.min.js"></script>

<script src="../../resource/lib/cityPicker/citydata.min.js"></script>
<script src="../../resource/lib/cityPicker/cityPicker-2.0.3.js"></script>

<script src="../../resource/lib/imageview/js/imageviewer.min.js"></script>

<script src="../../js/stagent.uri.constant.js"></script>
<script src="../../resource/js/plugins/hot/Jquery.util.js" th:src="@{/resource/js/plugins/hot/Jquery.util.js?20181207055}"></script>
<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/stats/goodsSaleStats}]]*/  "";
</script>

<script src="https://cdn.bootcss.com/Mock.js/1.0.0/mock-min.js"></script>

<script>
    $(function () {
        $(".data-range-pick-custom").daterangepicker({
            locale: {
                format: 'YYYY-MM-DD'
            }
        });
        $(".data-range-pick-custom").on('cancel.daterangepicker', function (ev, picker) {
            $(this).val("");
        });

        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });
    var isComplated = true;
    var saleGoodsList = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        exportExcel: function () {
            var param = location.search;
            window.location.href = "exportGoodsSaleExcel.xls?" + param;
        },
        setStoreCount: function (dataId) {
            $("#goodsId").val(dataId);
        },
        btnSubmit: function () {
            if (!isComplated) {
                return false;
            }
            isComplated=false;
            var self = this;
            var count = $.trim($("#storeCount").val());
            if (hotUtil.isNullOrEmpty(count) || isNaN(parseInt(count))) {
                hot.tip.error("库存只能是整数！");
                return;
            }
            hot.loading.show();
            hotUtil.ajaxCall("/goods/ajax/changeStoreCount", {
                goodsId: $("#goodsId").val(),
                count: count,
                remark: $("#remark").val()
            }, function (ret) {
                hot.loading.close();
                if (ret.resultCode === 2000) {
                    hot.tip.success("保存成功！", function () {
                        self.searchAll();
                    });
                }
                else {
                    hot.tip.error(ret.resultMsg);
                }
            });
        }
    };
</script>
</body>
</html>
